package org.example.heterogeneous;

import org.example.heterogeneous.readData.FoursquareData;
import org.example.heterogeneous.readData.TrussExample;

import java.util.*;

public class testTruss {
    public static void main(String[] args) {
        //testBasicBTrussExampleData();
        testFastBTrussExampleData();
    }

    public static void testBasicBTrussExampleData() {
        // 输入参数
        int k = 5;
        String q = "a4";
        int targetType = TrussExample.A_TYPE;
        List<Integer> metaPath = new ArrayList<>();
        metaPath.add(TrussExample.A_TYPE);
        metaPath.add(TrussExample.P_TYPE);
        metaPath.add(TrussExample.A_TYPE);

        // 读取数据
        TrussExample trussExample = new TrussExample();
        trussExample.read();

        TrussCommunity trussCommunity = new TrussCommunity(trussExample.getEdgeList(), trussExample.getNodeList(), trussExample.getAdjacencyEdgeList(), trussExample.getFirst());
        trussCommunity.basicBTruss(metaPath, q, targetType, k);
    }

    public static void testFastBTrussExampleData() {
        // 输入参数
        int k = 4;
        String q = "a4";
        int targetType = TrussExample.A_TYPE;
        List<Integer> metaPath = new ArrayList<>();
        metaPath.add(TrussExample.A_TYPE);
        metaPath.add(TrussExample.P_TYPE);
        metaPath.add(TrussExample.A_TYPE);

        // 读取数据
        TrussExample trussExample = new TrussExample();
        trussExample.read();

        TrussCommunity trussCommunity = new TrussCommunity(trussExample.getEdgeList(), trussExample.getNodeList(), trussExample.getAdjacencyEdgeList(), trussExample.getFirst());
        trussCommunity.fastBTruss(metaPath, q, targetType, k);
    }

    public static void testBasicBTrussSmallScaleFoursquareData() {
        // 输入参数
        int k = 4;
        String q = "999";
        int targetType = 1;
        List<Integer> metaPath = new ArrayList<>();
        metaPath.add(1);
        metaPath.add(2);
        metaPath.add(1);

        // 读取数据
        FoursquareData foursquareData = new FoursquareData();
        String prefixPath = "./src/main/java/org/example/heterogeneous/data/";
        String fileName = "testData.txt";
        String inputFileName = prefixPath + fileName;
        String outputFileName = prefixPath + "result-" + fileName;
        String regex = "\t";
        foursquareData.readTSMC2014(inputFileName, regex);

        TrussCommunity trussCommunity = new TrussCommunity(foursquareData.getEdgeList(), foursquareData.getNodeList(), foursquareData.getAdjacencyEdgeList(), foursquareData.getFirst());
        trussCommunity.basicBTruss(metaPath, q, targetType, k);
    }

    public static void testFastBTrussSmallScaleFoursquareData() {
        // 输入参数
        int k = 4;
        String q = "87";
        int targetType = 1;
        List<Integer> metaPath = new ArrayList<>();
        metaPath.add(1);
        metaPath.add(2);
        metaPath.add(1);

        // 读取数据
        FoursquareData foursquareData = new FoursquareData();
        String prefixPath = "./src/main/java/org/example/heterogeneous/data/";
        String fileName = "testData.txt";
        String inputFileName = prefixPath + fileName;
        String outputFileName = prefixPath + "result-" + fileName;
        String regex = "\t";
        foursquareData.readTSMC2014(inputFileName, regex);

        TrussCommunity trussCommunity = new TrussCommunity(foursquareData.getEdgeList(), foursquareData.getNodeList(), foursquareData.getAdjacencyEdgeList(), foursquareData.getFirst());
        trussCommunity.fastBTruss(metaPath, q, targetType, k);

    }

    public static void testFastBTruss() {
        // 输入参数
        int k = 20;
        String q = "748";
        int targetType = 1;
        List<Integer> metaPath = new ArrayList<>();
        metaPath.add(1);
        metaPath.add(2);
        metaPath.add(1);

        // 读取数据
        FoursquareData foursquareData = new FoursquareData();
        String prefixPath = "./src/main/java/org/example/heterogeneous/data/";
        String fileName = "dataset_ubicomp2013_checkins.txt";
        String inputFileName = prefixPath + fileName;
        String outputFileName = prefixPath + "result-" + fileName;
        String regex = "\t";
        foursquareData.readubicomp2013(inputFileName, regex);

        TrussCommunity trussCommunity = new TrussCommunity(foursquareData.getEdgeList(), foursquareData.getNodeList(), foursquareData.getAdjacencyEdgeList(), foursquareData.getFirst());
        trussCommunity.fastBTruss(metaPath, q, targetType, k);
    }

    public static void testBasicBTruss() {
        // 输入参数
        int k = 20;
        String q = "748";
        int targetType = 1;
        List<Integer> metaPath = new ArrayList<>();
        metaPath.add(1);
        metaPath.add(2);
        metaPath.add(1);

        // 读取数据
        FoursquareData foursquareData = new FoursquareData();
        String prefixPath = "./src/main/java/org/example/heterogeneous/data/";
        String fileName = "dataset_ubicomp2013_checkins.txt";
        String inputFileName = prefixPath + fileName;
        String outputFileName = prefixPath + "result-" + fileName;
        String regex = "\t";
        foursquareData.readubicomp2013(inputFileName, regex);

        TrussCommunity trussCommunity = new TrussCommunity(foursquareData.getEdgeList(), foursquareData.getNodeList(), foursquareData.getAdjacencyEdgeList(), foursquareData.getFirst());
        trussCommunity.basicBTruss(metaPath, q, targetType, k);
    }

    public static void testInput() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入k：");
        int k;
        k = scanner.nextInt();

        System.out.println("请输入要查询的顶点：");
        String q;
        q = scanner.next();

        System.out.println("请输入要查询的顶点类型（1-user，2-venue，3-venueCategory）：");
        int targetType;
        targetType = scanner.nextInt();

        System.out.println("请输入原路径（原路径为顶点类型，一行一行输入，以'#'结束）：");
        List<Integer> metaPath = new ArrayList<>();
        String str = scanner.next();
        while (!"#".equals(str)) {
            metaPath.add(Integer.parseInt(str));
            str = scanner.nextLine();
        }
        System.out.print("输入的原路径为：");
        int size = metaPath.size();
        for (int i = 0; i < size; ++i) {
            Integer path = metaPath.get(i);
            System.out.printf("%d", path);
            if (i != size - 1) {
                System.out.print("->");
            }
        }
        System.out.println();
    }

    public static void testReadFoursquareData() {
        FoursquareData foursquareData = new FoursquareData();

        String inputFileName = "./src/main/java/org/example/heterogeneous/data/dataset_ubicomp2013_checkins.txt";
        String regex = "\t";
        foursquareData.readubicomp2013(inputFileName, regex);

        List<Node> nodeList = foursquareData.getNodeList();
        for (Node node : nodeList) {
            System.out.println(node.toString());
        }

        List<Edge> edgeList = foursquareData.getEdgeList();
        for (Edge edge : edgeList) {
            System.out.println(edge.getU() + "-" + edge.getV());
        }
        System.out.println("边的数量为" + edgeList.size());
    }

    public static void testListSort() {
        List<Node> nodeListGp = new ArrayList<>();
        Node node = new Node(0, 1, "000");
        nodeListGp.add(node);
        node = new Node(1, 1, "111");
        nodeListGp.add(node);
        node = new Node(2, 1, "222");
        nodeListGp.add(node);
        node = new Node(3, 1, "333");
        nodeListGp.add(node);
        node = new Node(4, 1, "444");
        nodeListGp.add(node);

        int[] degreeGp = new int[101];
        degreeGp[0] = 3;
        degreeGp[1] = 1;
        degreeGp[2] = 5454;
        degreeGp[3] = 0;
        degreeGp[4] = 23;

        System.out.println("排序前");
        for (Node temp : nodeListGp) {
            System.out.print(temp);
            System.out.print("--");
            System.out.println(degreeGp[temp.getId()]);
        }

        Collections.sort(nodeListGp, new Comparator<Node>() {
            @Override
            public int compare(Node u, Node v) {
                return degreeGp[u.getId()] - degreeGp[v.getId()];
            }
        });

        System.out.println("排序后");
        for (Node temp : nodeListGp) {
            System.out.print(temp);
            System.out.print("--");
            System.out.println(degreeGp[temp.getId()]);
        }
    }


}
